﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace YSCommander
{
	/// <summary>
	/// Interaction logic for SectionWindow.xaml
	/// </summary>
	public partial class SectionWindow : Window
	{
		#region Fields
		#endregion Fields

		#region Properties

		/// <summary>
		/// Gets or sets the ProgramName.
		/// </summary>
		public String SectionName
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the Commander Data.
		/// </summary>
		public YSCommander.Data.CommanderData CommanderData
		{
			get;
			set;
		}
		#endregion Properties

		#region Methods

		/// <summary>
		/// Create the new instance.
		/// </summary>
		public SectionWindow()
		{
			InitializeComponent();

			SectionName = "";
			textBoxName.DataContext = this;

		}

		/// <summary>
		/// Handles the "OK" button event.
		/// </summary>
		/// <param name="sender">Sender.</param>
		/// <param name="e">Event arguments.</param>
		private void buttonOK_Click(object sender, RoutedEventArgs e)
		{
			DialogResult = true;
		}

		/// <summary>
		/// Handles the "window loaded" event. Sets the focus on name field.
		/// </summary>
		/// <param name="sender">Sender.</param>
		/// <param name="e">Event arguments.</param>
		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			textBoxName.Focus();
		}

		/// <summary>
		/// Handles the "text changed" event.
		/// </summary>
		/// <param name="sender">Sender.</param>
		/// <param name="e">Event arguments.</param>
		private void textBoxName_TextChanged(object sender, TextChangedEventArgs e)
		{
			bool valid = (null != CommanderData);
			if (valid && 0 < textBoxName.Text.Length)
			{
				buttonOK.IsEnabled = !CommanderData.IsSectionExists(textBoxName.Text);
			}
			else
			{
				buttonOK.IsEnabled = false;
			}
		}

		#endregion Methods
	}
}
